package lab03.test08;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by dell on 2017/12/7.
 */
public class Test {
    public static void main(String[] args) {
        String file1="D:\\file1.txt";
        String file2="D:\\file2.txt";
        String file3="D:\\file3.txt";

        //字节流读文件
        FileInputStream file1InputStream=null;
        FileInputStream file2InputStream=null;


        //字节流写文件
        FileOutputStream file3OutputStream=null;

            try {
                file1InputStream=new FileInputStream(file1);
                file2InputStream=new FileInputStream(file2);

                int data1;
                int data2=0;

                while(
                        ((data1=file1InputStream.read())!=-1)
                        || ((data2=file2InputStream.read())!=-1)
                        ){
                    file3OutputStream.write(data1);
                    file3OutputStream.write(data2);
                }


            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    file1InputStream.close();
                    file2InputStream.close();
                    file3OutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }

    }
    }

